package com.huarui.payable.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.dao.impl.BaseDaoImpl;
import org.springframework.orm.ibatis.SqlMapClientCallback;

import com.huarui.payable.dao.IPayableDao;
import com.huarui.payable.model.Payable;
import com.ibatis.sqlmap.client.SqlMapExecutor;

public class PayableDaoImpl extends BaseDaoImpl implements IPayableDao{

	@SuppressWarnings("unchecked")
	@Override
	public Integer getByConditionsForCount(Map map) {
		
		return (Integer) this.getSqlMapClientTemplate().queryForObject(namespace+".getByConditionsForCount",map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map> getByConditions(Map map) {
		
		return this.getSqlMapClientTemplate().queryForList(namespace+".getByConditions",map);
	}
      
	public void createPayable(Payable payable){
		super.create(payable);
	}

	@Override
	public void batchInsertPayable(final List<Payable> payables) {
		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
			
			@Override
			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
				executor.startBatch();
				for(Payable payable : payables){
					executor.insert(namespace+".create", payable);
				}
			    executor.executeBatch();
			    return null;
			}
		});		
	}
}
